<template>
  <div>
    <el-breadcrumb>
      <el-breadcrumb-item> <span class="headerSpan"></span>商品列表<el-button size="small" icon="el-icon-refresh">刷新</el-button></el-breadcrumb-item>
    </el-breadcrumb>
    <div class="content">
      <div>
        <el-button type="primary" v-for="(item, index) in navData.data" :key="index">{{ item.name }}({{ item.count }})</el-button>
      </div>
      <div class="search">
        <p style="float:left"><i class="el-icon-search" style="fontSize:20px;fontWeight:700"></i><span>筛选选择</span></p>
        <p style="float:right">
          <i class="el-icon-caret-bottom"></i><span style="marginRight:10px">收起筛选</span> <button @click="searchResult()">查询结果</button><button @click="isShowRetrieval = true">高级检索</button>
        </p>
      </div>
      <div class="searchContent">
        <div style="display:flex; align-items: center;"><span style="width:100px;">输入搜索:</span><el-input placeholder="请输入内容" v-model="searchName"></el-input></div>

        <div>
          <span>商品分类:</span>
          <el-select v-model="searchCateID" placeholder="请选择">
            <el-option v-for="item in cateData" :key="item.id" :label="item.name" :value="item.id"> </el-option>
          </el-select>
        </div>
        <div>
          <span>商品品牌:</span>
          <el-select v-model="value" placeholder="请选择"> </el-select>
        </div>
      </div>
      <div class="search">
        <p style="float:left"><i class="el-icon-tickets" style="fontSize:20px;fontWeight:700"></i><span>数据列表</span></p>
        <p style="float:right">
          <button style="marginRight:8px;">修改基本信息</button>
          <button style="marginRight:8px;">修改商品详情</button>
          <el-select v-model="value" placeholder="显示条数" size="mini" style="width:100px;marginRight:8px;"> </el-select>
          <el-select v-model="value" placeholder="排列顺序" size="mini" style="width:100px;"> </el-select>
        </p>
      </div>
      <el-table :data="tableData" border style="width: 100%;fontSize:12px">
        <el-table-column align="center" type="selection" width="55"> </el-table-column>
        <el-table-column align="center" prop="id" label="编号" width="100"> </el-table-column>
        <el-table-column align="center" prop="image" label="商品图片" width="100">
          <template slot-scope="scope" width="100"> <img :src="scope.row.image" /> </template>
        </el-table-column>
        <el-table-column align="center" prop="name" width="210" label="商品名称"> </el-table-column>
        <el-table-column align="center" prop="sn" label="价格/货号">
          <template slot-scope="scope" width="100">
            <span style="fontSize:12px">货号:{{ scope.row.sn }} </span></template
          >
        </el-table-column>
        <el-table-column align="center" prop="is_marketable" label="标签">
          <template slot-scope="scope"> 上架:<el-switch v-model="scope.row.is_marketable"> </el-switch> </template
        ></el-table-column>
        <el-table-column align="center" prop="id" label="SKU库存">
          <template slot-scope="scope">
            <i style="fontSize:30px;color:#0099FF" @click="skuSearch(scope.row.id, scope.row.sn)" class="el-icon-edit-outline"></i>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="sale_num" label="销量"> </el-table-column>
        <el-table-column align="center" prop="status" label="审核状态">
          <template slot-scope="scope">
            <span v-if="scope.row.status">已审核</span>
            <span v-else>待审核</span>
            <p style="padding:0;margin:0;color:#0099FF">查看详情</p>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="status" label="操作">
          <template>
            <p><i>编辑</i> <i>日志</i></p>
            <p><i>查看</i> <i>删除</i></p>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :page-sizes="[5, 8, 10]"
        :page-size="pageSize"
        :current-page="page"
        @size-change="pageChange()"
        @current-change="pageChange()"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableLenght"
      >
      </el-pagination>
    </div>
    <!-- 高级检索 -->
    <el-dialog title="高级检索" :visible.sync="isShowRetrieval" width="40%">
      <el-form :inline="true" label-position="top" class="demo-form-inline">
        <el-form-item label="商品分类：">
          <el-input placeholder="审批人"></el-input>
        </el-form-item>
        <el-form-item label="商品品牌：">
          <el-input placeholder="审批人"></el-input>
        </el-form-item>
        <el-form-item label="标签：">
          <el-input placeholder="审批人"></el-input>
        </el-form-item>
        <el-form-item label="上下架：">
          <el-input placeholder="审批人"></el-input>
        </el-form-item>
        <el-form-item label="审核状态：">
          <el-input placeholder="审批人"></el-input>
        </el-form-item>
        <el-form-item label="输入搜索：">
          <el-input placeholder="审批人"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isShowRetrieval = false">取 消</el-button>
        <el-button type="primary" @click="isShowRetrieval = false">检 索</el-button>
      </span>
    </el-dialog>
    <!-- SKU库存查询 -->
    <el-dialog title="编辑货品信息" :visible.sync="SKUisShow" width="65%">
      <el-row :gutter="20">
        <el-col :span="7">商品货号:{{ SkuSn }}</el-col>
        <el-col :span="17">
          <el-input placeholder="按SKU编号搜索" class="input-with-select"> <el-button slot="append" icon="el-icon-search"></el-button> </el-input
        ></el-col>
      </el-row>
      <template>
        <el-table :data="SkutabelData" border style="width: 100%;marginTop:25px">
          <el-table-column prop="date" label="SKU编号">
            <template slot-scope="scope"> <el-input v-model="scope.row.id"></el-input> </template
          ></el-table-column>
          <el-table-column prop="spec" label="尺码">
            <template slot-scope="scope">{{ scope.row.spec.rule }}</template>
          </el-table-column>
          <el-table-column label="颜色">
            <template slot-scope="scope">{{ scope.row.spec.color }}</template>
          </el-table-column>
          <el-table-column label="销售价格">
            <template slot-scope="scope"> <el-input v-model="scope.row.price"></el-input> </template>
          </el-table-column>
          <el-table-column label="商品库存">
            <template slot-scope="scope"> <el-input v-model="scope.row.num"></el-input> </template>
          </el-table-column>
          <el-table-column label="库存预警值">
            <template slot-scope="scope"> <el-input v-model="scope.row.alert_num"></el-input> </template>
          </el-table-column>
        </el-table>
      </template>
      <span slot="footer" class="dialog-footer">
        <el-button @click="SKUisShow = false">取 消</el-button>
        <el-button type="primary" @click="SKUisShow = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      value: '',
      tableData: [],
      tableLenght: 0,
      isShowRetrieval: false,
      navData: '',
      searchName: '',
      searchCateID: '',
      cateData: '',
      pageSize: 10,
      page: 1,
      SKUisShow: false,
      SkuIDsearch: '',
      SkuSn: '',
      SkutabelData: []
    }
  },
  methods: {
    // 获取数据列表
    async getListData() {
      const res = await this.$http.get(`/category/findPage/${this.page}/${this.pageSize}`, {
        params: {
          name: this.searchName,
          category1_id: this.searchCateID,
          brand_id: '',
          sn: ''
        }
      })
      console.log(res)
      this.tableData = res.data.data
      this.tableLenght = res.data.data.length
    },
    // 获取导航数据
    async getFindState() {
      const { data: res } = await this.$http.get('/category/findState')
      this.navData = res.data
    },
    // 获取分类下拉数据
    async getCateData() {
      const { data: res } = await this.$http.get('/category')
      this.cateData = res.data.PageResult.rows
      // console.log(res.data.PageResult.rows)
      // console.log(this.cateData)
    },
    // 获取Sku的相应货品数据
    async getSkuData() {
      const { data: res } = await this.$http.get(`/sku/findall/${this.SkuIDsearch}`)
      // console.log(res.data.pageresult.rows)
      this.SkutabelData = res.data.pageresult.rows
    },
    // 查询结果事件
    searchResult() {
      this.getListData()
    },
    // 页面发生改变时触发
    pageChange() {
      this.getListData()
    },
    // sku弹框事件
    skuSearch(id, sn) {
      this.SKUisShow = true
      this.SkuIDsearch = id
      this.SkuSn = sn
      this.getSkuData()
    }
  },
  created() {
    this.getListData()
    this.getFindState()
    this.getCateData()
  }
}
</script>
<style lang="less" scoped>
.content {
  padding-bottom: 100px;
  margin: 20px;
  margin-right: 40px;
  width: 90%;
  .el-button {
    height: 30px;
    line-height: 0;
    span {
      color: red;
    }
  }
  .search {
    margin-top: 20px;
    width: 100%;
    height: 50px;
    background-color: rgba(243, 243, 243, 1);
    padding: 0px 20px 0px;
    border: 1px solid #ccc;
    box-sizing: border-box;
    border-bottom: none;
    p {
      font-size: 12px;
    }
  }
  .searchContent {
    box-sizing: border-box;
    height: 80px;
    width: 100%;
    border: 1px solid #ccc;
    display: flex;
    justify-content: space-around;
    align-items: center;
    &div {
      &span:nth-child(1) {
        margin-left: 5px;
      }
    }
  }
}
</style>
